package org.real.guetshop.controller.general;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.real.guetshop.context.BaseContext;
import org.real.guetshop.propertis.JwtProperties;
import org.real.guetshop.result.Result;
import org.real.guetshop.utils.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/ref")
@Slf4j
public class AccessTokenRefreshController {

    @Resource
    private JwtProperties jwtProperties;

    @GetMapping
    public Result<String> getNewAccessToken() {
        log.info("{} getNewAccessToken...", BaseContext.getCurrentId());

        //获得当前时间的秒数
        long nowTime = System.currentTimeMillis();

        return Result.success(JwtUtil.createToken(BaseContext.getCurrentId()
                , new Date(nowTime)
                , new Date(nowTime + jwtProperties.getAdminTtl())));
    }
}
